* Stata/IC 14.2

set more off

* data
import delimited "C:\Users\battl\OneDrive\JUN\UC MERCED\Independent Research\local election and media freedom\data\clean\df2.csv", clear
destring year-lag_elsrgel_q10, replace force

gen gwf_case_duration2 = gwf_case_duration^2
gen gwf_case_duration3 = gwf_case_duration^3
gen natmsfs = lag_natelec*lag_msfs

global control "lag_gdp lag_growth lag_logoil lag_war lag_interwar lag_natelec lag_personalism gwf_case_duration gwf_case_duration2 gwf_case_duration3"

* Interflex (To run this function, please install the following packages)
*ssc install interflex, replace all
*ssc install reghdfe, replace all
*ssc install ftools, replace all

*------*
* Main *
*------*

* Figure 1
interflex noncivilfail lag_ellocelc_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_elsrgel_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xellocelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xelregelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)

*----------*
* Appendix *
*----------*

* Figure A5
interflex noncivilfail lag_ellocelc_q10 lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_elsrgel_q10 lag_msfs $control, fe(caseid year) cl(caseid) type(linear)

* Figure A6
interflex gwf_case_fail lag_ellocelc_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex gwf_case_fail lag_elsrgel_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex gwf_case_fail lag_xellocelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex gwf_case_fail lag_xelregelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)

* Figure A7
interflex noncivilfail lag_ellocelc_bi lag_msfs $control natmsfs, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_elsrgel_bi lag_msfs $control natmsfs, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xellocelec lag_msfs $control natmsfs, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xelregelec lag_msfs $control natmsfs, fe(caseid year) cl(caseid) type(linear)

* Figure A8
interflex e_polity2 lag_ellocelc_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex e_polity2 lag_elsrgel_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex e_polity2 lag_xellocelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex e_polity2 lag_xelregelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)

* Figure A9
drop if lag_natelec == 0
interflex noncivilfail lag_ellocelc_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_elsrgel_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xellocelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xelregelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)

* Figure A11
interflex noncivilfail lag_ellocelc_bi lag_msfs $control, fe(cid year) cl(cid) type(linear)
interflex noncivilfail lag_elsrgel_bi lag_msfs $control, fe(cid year) cl(cid) type(linear)
interflex noncivilfail lag_xellocelec lag_msfs $control, fe(cid year) cl(cid) type(linear)
interflex noncivilfail lag_xelregelec lag_msfs $control, fe(cid year) cl(cid) type(linear)
interflex noncivilfail lag_natelec lag_msfs $control2, fe(cid year) cl(cid) type(linear)


* Figure A10
import delimited "C:/Users/battl/OneDrive/JUN/UC MERCED/Independent Research/local election and media freedom/data/clean/imputation.csv", clear
destring year-caseid, replace force

gen gwf_case_duration2 = gwf_case_duration^2
gen gwf_case_duration3 = gwf_case_duration^3
gen natmsfs = lag_natelec*lag_msfs

global control "lag_gdp lag_growth lag_logoil lag_war lag_interwar lag_natelec lag_personalism gwf_case_duration gwf_case_duration2 gwf_case_duration3"

interflex noncivilfail lag_ellocelc_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_elsrgel_bi lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xellocelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)
interflex noncivilfail lag_xelregelec lag_msfs $control, fe(caseid year) cl(caseid) type(linear)

